export default {
    install(Vue, options) {
        Vue.prototype.formatHttpGetParams = function (obj) {
            var params = "?"
            for (var p in obj) {
                if (typeof (obj[p]) == " function ") {
                    params += p + "=" + obj[p]() + "&"
                } else {
                    params += p + "=" + obj[p] + "&"
                }
            }
            return params.substr(0, params.length - 1)
        }

        Vue.prototype.setCookie = function (name, value) {
            var Days = 30
            var exp = new Date()
            exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000)
            document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString()
        }

        Vue.prototype.getCookie = function (name) {
            var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)")
            if (arr = document.cookie.match(reg))
                return unescape(arr[2])
            else
                return null
        }

        Vue.prototype.delCookie = function (name) {
            var exp = new Date()
            exp.setTime(exp.getTime() - 1)
            var cval = getCookie(name)
            if (cval != null)
                document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString()
        }

        Vue.prototype.checkTime = function (i) {
            if (i < 10) {
                return '0' + i
            }
            return i
        }

        Vue.prototype.checkDemical = function (value) {
            let patrn = /^\d+(\.\d+)?$/
            if (patrn.exec(value)) {
                return true
            }
            return false
        }

        Vue.prototype.GMT2Date = function (mGMT) {
            let date = new Date(mGMT)
            let y = date.getFullYear()
            let M = date.getMonth() + 1
            let d = date.getDate()
            if (M < 10) {
                M = '0' + M
            }
            if (d < 10) {
                d = '0' + d
            }
            return y + '' + M + '' + d
        }

        Vue.prototype.hasMenu = function (menuList, id) {
            for (let i = 0; i < menuList.length; i++) {
                let item = menuList[i]
                if (item.id && item.id == id) {
                    return true
                }
            }
            return false
        }
    }
}